<template>
	<xbd-pages-content title="title">
		<template #content>
			<view class="content" :style="'minHeight:'+windowHeight+'px'">
				<view class="box" v-for="(item,index1) in list " :key ="index1" >
					<view class="box_title">
						<xbd-title title="体检时间">
							<template #default>
								<view class="title_right">
									{{item.time}}
								</view>
							</template>
						</xbd-title>
					</view>
					<view class="box_item" v-for="(item2 ,index2) in  item.data " :key="index2">
						<view class="left">
							{{item2.key}}：
						</view>
						<view class="right">
							{{item2.value}}
						</view>
					</view>
				</view>
				<view>
				<xbd-null-list v-if="!list.length"></xbd-null-list>
				<xbd-loading-more :status-num="statusNum" :is-load-more="isLoadMore" @more="loadmore"></xbd-loading-more>
				</view>

				
			</view>
		</template>
	</xbd-pages-content>
</template>

<script>
	import { Health } from '@/api/index.js';
	export default {
		data(){
			return{
				title:'',
				type:'',
				windowHeight:0,
				statusNum: 0,
				isLoadMore: false,
				queryInfo:{
					type:'',
					page:0,
					perpage:10
				},
				list:[
				]
			}
		},
	methods:{
		// 初始化数据
		
		async getList() {
			try {
				this.$showLoading('加载中');
				const res = await Health.getTypeList(this.queryInfo);
				uni.hideLoading();
				
				this.list = res.data.list
				if(res.data.list.length === this.queryInfo.perpage){
					this.isLoadMore = true;
					this.statusNum = 2;
				}
			}catch(e) {
				uni.hideLoading();
			}
		},
		
		loadmore() {
			    this.queryInfo.page++;
				this.statusNum = 1;
				this.isLoadMore = true;
				this.loadmoreList();
				
		},
		async loadmoreList() {
			
			try {
				const res = await Health.getTypeList(this.queryInfo);
				if (res.success) {
					this.list = this.list.concat(res.data.list)
					if(res.data.list.length === this.queryInfo.perpage){
						this.statusNum = 2;
					}else{
						this.statusNum = 0;
					}
					// this.isLoadMore = false;
				} else {
					this.queryInfo.page--;
					this.statusNum = 2;
				}
			} catch(e) {
				this.queryInfo.page--;
			}
		},
	},

	onLoad(res){
		this.title=res.title
		if(res.title === '心理健康'){
			this.queryInfo.type = 'Mental'
		}else{
			this.queryInfo.type = 'tcm'
		}
		uni.setNavigationBarTitle({
		    title: res.title
		});
		uni.getSystemInfo({
		    success:(res) =>{
				this.windowHeight = res.windowHeight
		    }
		});
		this.getList()
	},
	// 触底加载
	onReachBottom() {
		if (this.isLoadMore && this.statusNum !== 0) {
			this.loadmore();
		}
	}
}
</script>

<style lang="scss" scoped>
	.content{
		box-sizing: border-box;
		padding:50rpx;
		background-color: #FFFFFF;
		// box-sizing: border-box;
		.title_right{
			font-size: 28rpx;
			color: #39D4D1;
		}
		.box{
			margin-bottom: 20px;
			.box_title{
				box-sizing: border-box;
				border-bottom: 2rpx solid #E8E2E2;
				padding: 10px 0;
			}
			.box_item{
				display: flex;
				box-sizing: border-box;
				border-bottom: 2rpx solid #E8E2E2;
				padding: 10px 30rpx;
				.left{
					width: 250rpx;
					font-size: 32rpx;
					color: #3C6FFF;
					margin-right: 20rpx;
				}
				.right{
					flex: 1;
					font-size: 32rpx;
					color: #222222;
				}
			}
			
		}
	}
</style>
